package academic.emailClient.persistence;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;

import org.junit.Before;
import org.junit.Test;

public class TemplateTesting {
	
	private static String PATH = ".\\Templates";
	TemplateFileDAO template;
	String fileName="\\Testing.vm";
	File file=new File(PATH+fileName);	

	
	@Before
	public void initialize(){		
		template=new TemplateFileDAO();
	}
	
	@Test
	public void templateCreationTest(){
		boolean fileCreated=false;
		try{
			template.create("Testing", "Testing the template's creation");
			if(file.exists())
				fileCreated=true;
			assertTrue(fileCreated);
		}catch(IOException io){
			fail("File couldn't be created");
		}		
	}
	
	@Test
	public void templateOverwriteTest(){
		String templateContent= "Creating new testing Template";
		try{
			template.overwriteFile("Testing",templateContent);
			String path=PATH;
			String content=template.read(PATH,"Testing");
			assertTrue(template.read(PATH,"Testing").equals(content));
		}catch(IOException io){
			fail("File couldn't be created");
		}		
	}
	
	@Test
	public void templateDeleteTest(){
		String templateContent= "Creating new testing Template";
		template.delete(fileName);
		assertTrue(!file.exists());		
	}
	
}
